package task08;

import java.util.HashSet;
import java.util.Iterator;

/**
 * HashSetTest集合：元素无序唯一
 * @author Administrator
 * 无序：底层数据结构是使用哈希表
 * 唯一：通过equals()和hashcode()方法来保证的
 */
public class HashSetTest {
    public static void main(String[] args) {
        /*1.创建HashSet对象
        * 2.给集合对象添加元素
        * 3.遍历集合元素*/
        HashSet<Student> studentHashSet=new HashSet<Student>();
        Student s1=new Student( "rose",18);
        Student s2=new Student( "rose",18);
        Student s3=new Student( "rose",20);
        studentHashSet.add(s1);
        studentHashSet.add(s2);
        studentHashSet.add(s3);

        Iterator iterator=studentHashSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        /*HashSet<String> stringHashSet=new HashSet<String>();
        stringHashSet.add("张三");
        stringHashSet.add("李斯");
        stringHashSet.add("王五");*/
      /*  for(String s:stringHashSet){
            System.out.println(s);
        }*/
        /*Iterator iterator=stringHashSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }*/
        /*for(int i=0;i<stringHashSet.size();i++){
            System.out.println(stringHashSet.get(i));
        }*/
    }
}
